﻿package 
{
	import com.humansampler.jpo.collections.PointCollection;
	import com.humansampler.jpo.events.SampleEvent;
	import com.humansampler.jpo.models.HumanPoint;
	import com.humansampler.jpo.models.PointModel;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	/**
	 * ...
	 * @author ZoulouX
	 */
	public class Main extends Sprite 
	{
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			test();
		}
		
		public function test ():void
		{
			// Créer le model
			var model:PointModel = new PointModel();
			
			// Ecouter les modifications
			model.addEventListener(SampleEvent.REFRESH, sampleHandler);
			
			// Créer le vecteur
			var vector:Vector.<HumanPoint> = new Vector.<HumanPoint>();
			
			// Ajouter des points
			vector.push(new HumanPoint(5, 6, 40, 60, 0x56789));
			vector.push(new HumanPoint(5, 6, 40, 60, 0x56789));
			vector.push(new HumanPoint(5, 6, 40, 60, 0x56789));
			vector.push(new HumanPoint(5, 6, 40, 60, 0x56789));
			
			// Définir les points
			model.setPoints(vector);
		}
		
		public function sampleHandler (event:SampleEvent):void
		{
			trace("-> sampleHandler");
			
			for each (var point:HumanPoint in event.pointsCollection.points) 
			{
				trace(point);
			}
		}
	}
}